GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch feature/parse-icls-file (ad7e7c)
by Cedric
01:10
created

exports.parse   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
'use strict';
2
const xmljs = require('xml-js');
3
const Map = require('immutable').Map
0 ignored issues
show
Comprehensibility introduced by
You are shadowing the built-in type Map. This makes code hard to read, consider using a different name.
Loading history...
4
const List = require('immutable').List
5
const fromJS = require('immutable').fromJS
6
const autoCast = require('./utils').autoCast
7
const normalizeKey = require('./utils').normalizeKey
8
9
10
const cleanMap = function (map) {
11
    map = map.mapKeys(normalizeKey);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter map. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
12
    return map.map(autoCast);
13
}
14
15
let parseSchemeNode = function (el, store) {
16
    if (el.get('name') !== 'scheme' || !el.get('attributes')) {
17
        return store;
18
    }
19
20
    let attrs = el.get('attributes');
21
    attrs = cleanMap(attrs);
22
    return store.merge(attrs);
23
};
24
25
let parseOptionNode = function (el, store) {
26
    if (el.get('name') !== 'option' || !el.get('attributes')) {
27
        return store;
28
    }
29
30
    let attrs = new Map();
31
    attrs = attrs.set(el.getIn(['attributes', 'name']), el.getIn(['attributes', 'value']))
32
    attrs = cleanMap(attrs);
33
    return store.merge(attrs);
34
};
35
36
let parseColorNode = function (el, store) {
37
    if (el.get('name') !== 'colors') {
38
        return store;
39
    }
40
41
    return store.set('colors', readTree(el.get('elements'), new Map()))
42
};
43
44
let parseChildNodes = function (el, store) {
45
    if (!el.get('elements')) {
46
        return store;
47
    }
48
49
    for (let child of el.get('elements')) {
50
        store = store.merge(readTree(child, store));
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter store. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
51
    }
52
    return store;
53
};
54
55
const readTree = function (el, store) {
56
57
    if (List.isList(el)) {
58
        for (let element of el) {
59
            store = readTree(element, store);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter store. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
60
        }
61
        return store;
62
    }
63
64
    store = parseSchemeNode(el, store);
65
    store = parseOptionNode(el, store);
66
    store = parseColorNode(el, store);
67
    store = parseChildNodes(el, store);
68
69
    return store;
70
}
71
72
73
const buildTree = function (xmlObj) {
74
    let store = new Map();
75
    let rootNode = fromJS(xmlObj.elements[0]);
76
    return readTree(rootNode, store).toJS();
77
}
78
79
const convertToUnderstandable = function (xml) {
80
    return xmljs.xml2js(xml);
81
}
82
83
exports.parse = function (xml) {
84
    const jsObj = convertToUnderstandable(xml);
85
    return buildTree(jsObj);
86
}
87